<?php
namespace App\Service;
use Qiniu\Storage\UploadManager;
use Qiniu\Auth;

class QiNiuUpload
{
    public static function upload($file){
        $uploadMgr = new UploadManager();
        $auth = new Auth(env("QINIU_AKEY"), env("QINIU_SKEY"));
        $bucket=env("QINIU_BUCKET");
        $token = $auth->uploadToken($bucket);
        list($ret, $error) = $uploadMgr->putFile($token, $file, $file);
        if (isset($error)){
            return response()->json(['message'=>'上传失败']);
        }
        return env("QINIU_URL").'/'.$ret['key'].'-'.env('QINIU_STYLE');
    }
}


